/**
 * File: NodeActiveFilter.java
 * Created by: mhaimel
 * Created on: Apr 22, 2010
 * CVS:  $Id: NodeActiveFilter.java 1.0 Apr 22, 2010 12:25:57 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.model.graph.curtain.filter;

import java.util.concurrent.atomic.AtomicReference;

import uk.ac.ebi.curtain.model.graph.Node;
import uk.ac.ebi.curtain.model.graph.GraphAccess.TouchEach;
import uk.ac.ebi.curtain.model.graph.curtain.ContigInfo;
import uk.ac.ebi.curtain.model.graph.curtain.ReadWrapper;

/**
 * @author mhaimel
 *
 */
public class NodeActiveFilter implements TouchEach<Node<ContigInfo, ReadWrapper>> {

	private final AtomicReference<TouchEach<Node<ContigInfo, ReadWrapper>>> filter;
	private final boolean valid;
	public NodeActiveFilter(boolean allow, TouchEach<Node<ContigInfo, ReadWrapper>> filter) {
		this.filter = new AtomicReference<TouchEach<Node<ContigInfo, ReadWrapper>>>(filter);
		this.valid = allow;
	}
	
	@Override
	public void touch(Node<ContigInfo, ReadWrapper> node) {
		if(node.getActive().get() == this.valid){
			this.filter.get().touch(node);
		}
	}
}
